package com.lolong.hic;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ListView;

public class FavoritesActivity extends Activity implements OnItemClickListener, OnClickListener {

	private ImageButton backBtn;
	private ListView favoritesLView;
	private SQLiteConnector connector;
	
	private ArrayAdapter<String> listViewAdapter;
	private ArrayList<String> favorites;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.favorites);
		initComponents();
	}
	
	private void initComponents() {
		
		backBtn = (ImageButton) findViewById(R.id.back);
		backBtn.setOnClickListener(this);
		
		favorites = new ArrayList<String>();
		connector = new SQLiteConnector(this);
		
		favorites.addAll(connector.getFavorites());
		favoritesLView = (ListView) findViewById(R.id.favoriteListView);
		
		initListViewAdapter();

		favoritesLView.setAdapter(listViewAdapter);
		favoritesLView.setOnItemClickListener(this);
		
	}
	
	public void initListViewAdapter() {
		
		listViewAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1 , favorites);
		
	}
	
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		
		case R.id.back:
			Intent intent = new Intent(FavoritesActivity.this, CategoryActivity.class);
			startActivity(intent);
			break;
		
		}
		
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		
		Intent intent = new Intent(FavoritesActivity.this, InformationActivity.class);
		intent.putExtra("establishmentName", favoritesLView.getItemAtPosition(arg2).toString());
		startActivity(intent);
		
		
	}

	
	
}
